package pl.prv.polanie.client.dto;

import java.util.Comparator;

import com.google.gwt.user.client.rpc.IsSerializable;


/**
 * SubgroupDTO entity. @author MyEclipse Persistence Tools
 */

public class CSVSubgroupDTO extends java.lang.Object implements IsSerializable, ICSVDTO {


    // Fields    

	
	private long id;
     private String subgroupType;
     private String group;
     private String name;
     private Integer studentsNumber;


     
     
     private boolean highlighted;
     
     public static final int SORT_CONST__ID = 0;
     public static final int SORT_CONST__NAME = 1;
     public static final int SORT_CONST__STUDENTS_NUMBER = 2;
     public static final int SORT_CONST__SUBGROUP_TYPE = 3;
     public static final int SORT_CONST__GROUP = 4;

     
     
     
    // Constructors

    public CSVSubgroupDTO(long id, String subgroupType, String group, String name,
			Integer studentsNumber) {
		super();
		this.id = id;
		this.subgroupType = subgroupType;
		this.group = group;
		this.name = name;
		this.studentsNumber = studentsNumber;
	}


	/** default constructor */
    public CSVSubgroupDTO() {
    }

    
    /** full constructor */


    

	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public Integer getStudentsNumber() {
		return studentsNumber;
	}


	public void setStudentsNumber(Integer studentsNumber) {
		this.studentsNumber = studentsNumber;
	}

	public String toLabel() {
		String r;
		r = name + " (" + subgroupType + ", " + studentsNumber + ") " + group;
		return r;
	}
	
	public String toLabelShort() {
		String r;
		r = name + " (" + subgroupType + ", " + studentsNumber + ")";
		return r;
	}


	public String getSubgroupType() {
		return subgroupType;
	}


	public void setSubgroupType(String subgroupType) {
		this.subgroupType = subgroupType;
	}


	public String getGroup() {
		return group;
	}


	public void setGroup(String group) {
		this.group = group;
	}


	public long getId() {
		return id;
	}


	public void setId(long id) {
		this.id = id;
	}
	
	
	public String getField(int col) {
		if (col == SORT_CONST__ID) {
			return "" + getId();
		} else if (col == SORT_CONST__SUBGROUP_TYPE) {
			return "" + getSubgroupType();
		} else if (col == SORT_CONST__GROUP) {
			return "" + getGroup();
		} else if (col == SORT_CONST__NAME) {
			return "" + getName();
		} else if (col == SORT_CONST__STUDENTS_NUMBER) {
			return "" + getStudentsNumber();
		}
		return "no field";
	}


	@SuppressWarnings("unchecked")
	public static Comparator getComparator(final int colIndex) {
		Comparator cmp = new Comparator() {
			public int compare(Object o1, Object o2) {

//			    final int BEFORE = -1;
			    final int EQUAL = 0;
//			    final int AFTER = 1;
			    
			    CSVSubgroupDTO obj1;
			    CSVSubgroupDTO obj2;
			    if (o1 instanceof CSVSubgroupDTO && o2 instanceof CSVSubgroupDTO) {

					obj1 = (CSVSubgroupDTO) o1;
					obj2 = (CSVSubgroupDTO) o2;
					
					//this optimization is usually worthwhile, and can
					//always be added
					if ( obj1 == obj2 ) return EQUAL;

					//primitive numbers follow this form
					if (colIndex == SORT_CONST__ID) {
						Long l1 = new Long(obj1.getId());
						Long l2 = new Long(obj2.getId());
						return l1.compareTo(l2);
					} else if (colIndex == SORT_CONST__SUBGROUP_TYPE) {
						return obj1.getSubgroupType().compareTo(obj2.getSubgroupType());
					} else if (colIndex == SORT_CONST__NAME) {
						return obj1.getName().compareTo(obj2.getName());
					} else if (colIndex == SORT_CONST__GROUP) {
						return obj1.getGroup().compareTo(obj2.getGroup());
					} else if (colIndex == SORT_CONST__STUDENTS_NUMBER) {
						return obj1.getStudentsNumber().compareTo(obj2.getStudentsNumber());
					}
					
				};
				return EQUAL;
			}
		};

		return cmp;
	}

	
	
	public boolean isHighlighted() {
		return highlighted;
	}


	public void setHighlighted(boolean highlighted) {
		this.highlighted = highlighted;
	}
	
	
	
}